<?php
namespace Dashboard\Controller;
class LogsController extends BaseController{
    public function index(){
        $a        = (int)(I("currpage"));//跳转页数
        $sou      = I('sou');
        $pagesize = 15;
        if($a != null){
            $currpage = $a;
        }else{
            $currpage = isset($_GET['currpage'])?$_GET['currpage']:1;
        }
        if($sou){
            $totalpage = 1;
            $currpage  = 1;
            $list      = joinss("logs","a.*,b.name,b.numbers,b.img",array("a left join __ADMIN__ b on a.admin_id = b.id"),"a.admin_id = {$sou}","a.id desc");
        }else{
            //默认显示30天的日志
            $end_at = sel("logs","id,create_at","","id desc");
            $date   = $end_at['create_at']-(30*24*60*60);
            $result = currpages("logs","a.*,b.name,b.numbers,b.img",array("a left join __ADMIN__ b on a.admin_id = b.id"),"a.create_at >= {$date}","a.id desc",$pagesize,$currpage);
            $totalpage = $result['totalpage'];
            $list      = $result['list'];
            if($result['currpage']){
                $currpage = $result['currpage'];
            }
        }
        //管理员
        $admin = sels("admin");

        $this->assign("list",$list)->assign("currpage",$currpage)->assign("totalpage",$totalpage)->assign("admin",$admin);
        $this->display();
    }
    public function shan(){
        $start = strtotime(I('start'));
        $end   = strtotime(I('end'));
        if($start <= $end && $start != "" && $end != ""){
            //$res = del("logs","create_at >= {$start} and create_at < {$end}");
            $res = M("logs")->where("create_at >= {$start} and create_at < {$end}")->delete();
            if($res){
                $this->ajaxReturn(1);
            }else{
                $this->ajaxReturn(2);
            }
        }else{
            $this->ajaxReturn(3);
        }
    }
}